﻿using EM.OA.BLL;
using EM.OA.Common;
using EM.OA.DataModel.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace EM.OA.WebCommon.Base
{
    /// <summary>
    /// Controller基类,带权限
    /// </summary>
    public class BaseAuthController : BaseController
    {
        /// <summary>
        /// 当前登录用户
        /// </summary>
        public LoginUserEnt CurrentUser
        {
            get
            {
                if (Session["UserInfo"] == null)
                {
                    if (Session["UserID"] == null)
                    {
                        return new LoginUserEnt();
                    }
                    else
                    {
                        //根据登录的UserID取出登录信息
                        string userID = Session["UserID"].ToString();
                        UserBLL userBLL = new UserBLL();
                        EMOA_User entity = userBLL.GetEntity(Guid.Parse(userID));
                        LoginUserEnt LoginUserEnt= new LoginUserEnt
                        {
                            UserID = entity.UserID,
                            UserName = entity.UserName
                        };
                        Session["UserInfo"] = LoginUserEnt;
                        return LoginUserEnt;
                    }
                }
                else
                {
                    //如果已经登录，从Session里取
                    return Session["UserInfo"] as LoginUserEnt;
                }
            }
        }
    }
}
